package com.java2404.micro.merchant.handler;

import com.java2404.micro.common.dto.GoodsDTO;
import com.java2404.micro.common.entity.Goods;
import com.java2404.micro.common.entity.Merchant;
import com.java2404.micro.common.entity.PageBean;
import com.java2404.micro.common.resp.Result;
import com.java2404.micro.merchant.service.GoodsService;
import com.java2404.micro.merchant.service.MerchantService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
/**
 * 商品管理
 */
@Slf4j
@RestController
@RequestMapping("goods")
public class GoodsHandler {
    @Resource
    private GoodsService goodsService;
    /**
     * 分页展示商品
     */
    @GetMapping("/ShowGoods")
    public Result<PageBean<GoodsDTO>> ShowGoods(Integer pageNum, Integer pageSize){
        PageBean<GoodsDTO> page=goodsService.ShowGoods(pageNum,pageSize);
        return Result.success(page);}
    /**
     * 上传商品
     */
    @PostMapping("/add")
    public Result AddGoods(@RequestBody Goods goods){
        goodsService.AddGoods(goods);
        return Result.success();
    }
    /**
     * 下架商品
     */
    @DeleteMapping("/unsale")
    public Result unsalePro(Integer gid){
        goodsService.unsale(gid);
        return Result.success();
    }
    /**
     * 上架商品
     */
    @PutMapping("/sale")
    public Result salePro(Integer gid){
        goodsService.sale(gid);
        return Result.success();
    }

    /**
     * 根据商品id查询商品
     */
    @GetMapping("/getGoods/{gid}")
    public Result<GoodsDTO> getGoods(@PathVariable("gid") int gid){
        GoodsDTO goodsDTO =goodsService.getGoodsById(gid);
        return Result.success(goodsDTO);
    }
}
